<template>
	<view class="section">
		<view class="icon">
			<image src="../static/doc-call-bg.png"></image>
		</view>
		<view class="tip">
			<view class="title">请于工作时段联系医生</view>
			<view class="title">上午: {{am}}</view>
			<view class="title">下午: {{pm}}</view>
		</view>
		<view class="call-btn">
			拨打视频电话
		</view>
		<view class="call-btn-cancel">
			返回首页
		</view>
	</view>
</template>

<script>
	import dayjs from 'dayjs'
	export default {
		data() {
			return {
				am: "",
				pm: ""
			}
		},
		onLoad() {
			this.init()
		},
		methods: {
			init() {
				let tip = "08:00-11:00,13:30-17:00";
				if (tip) {
					let arr = tip.split(",")
					if (arr.length !== 2) {
						uni.showToast({
							icon: 'none',
							title: "时间格式不正确"
						})
						return
					} else {
						this.am = arr[0]
						this.pm = arr[1]
						let res= this.isWorkingTime(arr)
						console.log(res)
					}
				}

			},
			isWorkingTime(arr) {
				let am = arr[0].split("-")
				let pm = arr[1].split("-")
				const now = Date.now();
				let t1 = dayjs().format(`YYYY-MM-DD ${am[0]}:00`);
				let t2 = dayjs().format(`YYYY-MM-DD ${am[1]}:00`);
				let t3 = dayjs().format(`YYYY-MM-DD ${pm[0]}:00`);
				let t4 = dayjs().format(`YYYY-MM-DD ${pm[1]}:00`);
				return now >= dayjs(t1).valueOf() && now <= dayjs(t2).valueOf() ||
					now >= dayjs(t3).valueOf() && now <= dayjs(t4).valueOf()
			}
		}
	}
</script>

<style lang="scss" scoped>
	page {
		height: 100vh;
		display: flex;
		align-items: center;
		justify-content: center;
		// background: linear-gradient(to bottom, rgb(107, 175, 240), rgb(245, 137, 227));
	}

	.section {
		padding: 25px;
		
		.icon{
			>image{
				width: 250px;
				height: 222px;
			}
		}
	}

	.tip {
		text-align: center;
		font-size: 18px;
		line-height: 40px;
		margin-bottom: 40px;
		margin-top: 30px;
		color: #666;
	}

	.call-btn {
		padding: 15px;
		font-size: 16px;
		text-align: center;
		border-radius: 5px;
		margin: 10px 15px;
		font-weight: bold;
		background-color: #0063BC;
		color: #fff;
	}

	.call-btn-cancel {
		padding: 15px;
		font-size: 16px;
		text-align: center;
		border-radius: 5px;
		margin: 10px 15px;
		font-weight: bold;
		color: #333;
		// border: 1px solid #0063BC;
		// background-color: #f2f2f2;
	}
</style>